package Test;

import java.util.ArrayList;

import junit.framework.TestCase;
import officeserver.log_error.AppointmentException;
import officeserver.log_error.Log;
import officeserver.log_error.UserException;
import officeserver.office.AppointmentList;
import officeserver.office.Office;
import officeserver.report.Appointment;
import officeserver.report.Invoice;
import officeserver.report.LabWork;
import officeserver.report.Prescription;
import officeserver.report.Report;
import officeserver.report.Symptoms;
import officeserver.report.Treatment;
import officeserver.report.VitalSigns;
import officeserver.users.AccessLevel;
import officeserver.users.Patient;
import officeserver.users.PersonalInfo;
import officeserver.users.UserList;

/**
 * This is the JUnit test for confirmAppointment() method.
 * It will run a giant test for testing the 3 test cases in the test plan.
 * 
 * @author Matthew Ramsey
 *
 */
public class AppointmentConfirmTest extends TestCase {
	
	/**
	 * Creates an admin account for adding users 
	 */
	public void initAdmin() {
	try {
	    UserList.clear();
	    UserList.addUser("admin", "admin", "admin", "admin1",
		    AccessLevel.ADMIN);
	} catch (UserException e) {
	}
	}
	
	/**
	 * Test for confirmAppointment()
	 * 
	 * @throws Exception
	 */
	public void testConfirmAppointment() throws Exception{
	initAdmin();
		
	Office oTest = new Office(); 
	oTest.userLogin("admin", "admin1");
	oTest.addUser("Test", "Patient", "pat1", "pass1", AccessLevel.PATIENT);
	oTest.addUser("Test", "Nurse", "nurse1", "nursepass1", AccessLevel.NURSE);
	oTest.addUser("Test", "Doctor", "doc1", "docpass1", AccessLevel.DOCTOR);
	oTest.userLogout();
		
	oTest.userLogin("pat1", "pass1");
	oTest.addSelfAppointment(0, 100, 1);
	Appointment tempAppt = oTest.getSelfAppointments().get(0);
	
	oTest.userLogout();
	oTest.userLogin("nurse1", "nursepass1");
	oTest.userSearch("Test", "Patient");
	
	//First test to see if it's the right Appointment we're getting
	Appointment tempAppt2 = oTest.getWaitingAppointments().get(0);
	assertEquals(0, tempAppt2.getDoctorID());
	assertEquals(null, tempAppt2.getReport());
	assertEquals(100, tempAppt2.getDay());
	assertEquals(1, tempAppt2.getTimeSlot());
	assertEquals(false, tempAppt2.isConfirmed());
	assertEquals(tempAppt.getPatientID(), tempAppt2.getPatientID());
	assertEquals(tempAppt.getApptID(), tempAppt2.getApptID());
	
	oTest.confirmSearchUserAppointment(tempAppt2);
	Appointment tempAppt3 = oTest.getAppointmentsByDay(100).get(0);
	
	//Test #1: isConfirmed == true?
	assertEquals(true, tempAppt2.isConfirmed());
	
	//Test #2: Appointment removed from list?
	ArrayList <Appointment> appointments = oTest.getWaitingAppointments();
	boolean flag = false;
	for (Appointment appt : appointments) {
	    if (appt.getApptID() == tempAppt2.getApptID()) {
		flag = true;
	    }
	}
	assertFalse(flag);
	
	//Test #3: No Appointment exists?
	boolean flag2 = false;
	try{
		Appointment fakeAppt = new Appointment(null, 0, 0, 4, 1);
		oTest.confirmSearchUserAppointment(fakeAppt);
	} catch (AppointmentException e){
		flag2 = true;
	}
	assertFalse(!flag2);	
	}
}
